// TOWN SCRIPT
//    Town 7: Small town

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	change_blocked(10,15,1);
	change_blocked(11,15,1);
	change_blocked(12,15,1);
	change_blocked(13,15,1);
	
	change_blocked(10,16,1);
	change_blocked(11,16,1);
	change_blocked(12,16,1);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 11;
	if (get_flag(9,23) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"8.",0);
	add_dialog_str(1,"You are in a small town. Point B is in front of you. The direct route to Point B is obstructed. You must first reach Point A to activate Point B. A hostile monster blocks the route to Point B. A guard blocks the way to Point B.",0);
	add_dialog_str(2,"It is necessary to retrieve a special item before reaching Point B. You must reach Point B. Custom graphics and terrain scripts have been implemented. Creature scripts, cut scenes, and heights are added, too. The town has been expanded and complicated.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(9,23,250);
break;

beginstate 15;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2) {
		print_str("You activate Point B.");
		play_sound(99);
		set_flag(1,2,1);
		}
break;

beginstate 18;
	if (get_flag(1,2) == 0) {
		message_dialog("You have yet to activate Point B.","");
		block_entry(1);
		end();
		}
	
	set_flag(1,2,0);
	change_spec_item(27,-1);
	move_to_new_town(8,4,8);
break;

beginstate 19;
	if (get_flag(9,25) == 250)
		end();
	set_flag(9,25,250);
	message_dialog("The hostile monster appears.","");
	activate_hidden_group(5);
	
	put_boom_on_char(6,3,0);
	run_animation_sound(25);
	
	text_bubble_on_char(6,"RAARR!!");
	force_instant_terrain_redraw();
	pause(15);
	
	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"You die!!");
	force_instant_terrain_redraw();
	pause(15);
break;

beginstate 20;
	if (get_flag(9,27) == 250)
		end();
	set_flag(9,27,250);
	message_dialog("You retrieve the special item.","");
	change_spec_item(27,1);
	set_flag(9,11,1);
break;

beginstate 25;
if (char_ok(7)) {
	block_entry(1);
	message_dialog("The guard blocks your way.","");
	}
else {
	change_blocked(10,16,0);
	change_blocked(11,16,0);
	change_blocked(12,16,0);
	}
break;

beginstate 26;
if (get_flag(9,10) == 0) {
	set_flag(9,10,1);
	message_dialog("The special item is in the box.","");
	}
break;

beginstate 27;
if (get_terrain(19,9) != 29)
	end();

	if (get_flag(9,11) == 0) {
		message_dialog("You do not have the special item.","");
		block_entry(1);
		}
	else {
		message_dialog("You unlock the gates and open them.","");
		set_terrain(19,8,33);
		set_terrain(19,9,33);
		set_terrain(19,10,33);
		}
break;

beginstate 28;
	message_dialog("You can't go back this way.","");
	block_entry(1);
break;

beginstate 29;
	message_dialog("The monster screams as it dies.","");
break;

beginstate 30;
	message_dialog("The monster explodes.","");
break;